package action;

import Impl.TopicDaoImpl;
import entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet(name = "ModifyArticle",urlPatterns = "/modifyarticle.jhtml")
public class ModifyArticle extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        int sid = Integer.parseInt(request.getParameter("sid"));
        int tid = Integer.parseInt(request.getParameter("tid"));
        String author = request.getParameter("author");
        String sname = request.getParameter("sname");
        String topic=request.getParameter("topic");
        String content=request.getParameter("content");
        HttpSession session=request.getSession();
        User user = (User) session.getAttribute("user");
        int uid=user.getUid();
        TopicDaoImpl topicDao=new TopicDaoImpl();
        topicDao.modifyTopicInfo(topic,content,sid,uid,tid);
        String url="/showarticle.jhtml?tid="+tid+"&author="+author+"&&sname="+sname+"&&sid="+sid;
        System.out.println(url);
        request.getRequestDispatcher(url).forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    }
}
